layui.use(['layer', 'form', 'admin', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var upload = layui.upload;
    form.on("radio(questionIsReach)", function (data) {
        if (this.value == '否') {
            $("#auto").show();
        }
        else if (this.value == '是') {
            $("#auto").hide();
        }
    });
    form.on("radio(questionOneIsReach)", function (data) {
        if (this.value == '否') {
            $("#autoOne").show();
        }
        else if (this.value == '是') {
            $("#autoOne").hide();
        }
    });
    form.on("radio(questionTwoIsReach)", function (data) {
        if (this.value == '否') {
            $("#autoTwo").show();
        }
        else if (this.value == '是') {
            $("#autoTwo").hide();
        }
    });
    //获取当前用户上次的巡店沟通情况
    var xdgtAjax = new $ax(Feng.ctxPath + "/btyXdgt/lastInfo");
    var xdgtResult = xdgtAjax.start();
    var question=xdgtResult.question;
    $("#question").val(question);
    $("#gjmb").val(xdgtResult.gjmb);
    $("#questionOne").val(xdgtResult.questionOne);
    $("#gjmbOne").val(xdgtResult.gjmbOne);
    $("#questionTwo").val(xdgtResult.questionTwo);
    $("#gjmbTwo").val(xdgtResult.gjmbTwo);
    $("#questionThree").val(xdgtResult.questionThree);
    $("#gjmbThree").val(xdgtResult.gjmbThree);

    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyXdgt/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function( index, val ) {
        $("#dm").append("<option value='"+val.dm+"'>"+val.dm+"</option>");
    } );
    form.render('select');

    var ajax = new $ax(Feng.ctxPath + "/btyXdgt/info?id=" + $("#id").val());
    var result = ajax.start();
    form.val('noticeForm', result);



    var sumXd=0;
    var sumXds=0;

    var  flag=result.questionIsReach;
    if (flag == '否') {
        $("#auto").show();
    }
    else if (flag == '是') {
        sumXd+=2.5;
        sumXds+=3.33;
        $("#auto").hide();
    }else{
        $("#auto").hide();
    }

    var  flag1=result.questionOneIsReach;
    if (flag1 == '否') {
        $("#autoOne").show();
    }
    else if (flag1 == '是') {
        sumXd+=2.5;
        sumXds+=3.33;
        $("#autoOne").hide();
    }else{
        $("#autoOne").hide();
    }
    var  flag2=result.questionTwoIsReach;
    if (flag2 == '否') {
        $("#autoTwo").show();
    }
    else if (flag2 == '是') {
        sumXd+=2.5;
        sumXds+=3.33;
        $("#autoTwo").hide();
    }else {
        $("#autoTwo").hide();
    }
    form.render('select');
    //$("#sumXd").val(sumXd);
    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var gqhwlx=$("input[name='questionThreeIsReach']:checked").val();
        if(gqhwlx== undefined){
            sumXds=Math.round(sumXds);
            $("#sumXd").val(sumXds);
        }else{
            if (gqhwlx == '是') {
                sumXd+=2.5;
                $("#sumXd").val(sumXd);
            }
        }
        $("#sumXd").val(sumXd);


        var ajax = new $ax(Feng.ctxPath + "/btyXdgt/update", function (data) {
            Feng.success("修改成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.set("sumXd", $("#sumXd").val());
        ajax.start();
        //添加 return false 可成功跳转页面
        return false;
    });

});